package com.hyc.myvideo.ui.activity.home;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.flyco.tablayout.SlidingTabLayout;
import com.hyc.myvideo.R;
import com.hyc.myvideo.ui.base.BaseFActivity;
import com.hyc.myvideo.ui.base.BaseFragment;
import com.hyc.myvideo.ui.fragment.home.AllCourseFragment;
import com.hyc.myvideo.ui.fragment.home.FreeCourseFragment;
import com.hyc.myvideo.ui.fragment.home.PayCourseFragment;
import com.hyc.myvideo.ui.fragment.home.VIPCourseFragment;
import com.hyc.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 推荐课程
 * Created by dfeads on 2017/7/14.
 */

public class CourseActivity extends BaseFActivity {

  private final String[] mTitles = { "全部", "VIP", "付费", "免费" };
  private List<BaseFragment> fragments = new ArrayList<>();

  @BindView(R.id.activity_training_stl) SlidingTabLayout mTable;
  @BindView(R.id.activity_training_vp) ViewPager mPager;
  MyPagerAdapter mAdapter;

  private String curriculum_class_id = "";
  private String curriculum_class_title = "";

  public String getCurriculum_class_id() {
    return curriculum_class_id;
  }

  @Override public int getContentViewId() {
    return R.layout.activity_training;
  }

  @Override protected void initView() {
    curriculum_class_id = getIntent().getStringExtra("id");
    curriculum_class_title = getIntent().getStringExtra("title");
    if (!StringUtils.isEmpty(curriculum_class_title)) {
      setLeftBtnClick(true, curriculum_class_title);
    }
    setRightClick(R.mipmap.home_practice, new View.OnClickListener() {
      @Override public void onClick(View view) {
        startActivity(new Intent(CourseActivity.this, AudioActivity.class));
      }
    });

    fragments.add(new AllCourseFragment());
    fragments.add(new VIPCourseFragment());
    fragments.add(new PayCourseFragment());
    fragments.add(new FreeCourseFragment());
    mAdapter = new MyPagerAdapter(getSupportFragmentManager());
    mPager.setAdapter(mAdapter);
    mTable.setViewPager(mPager);
  }

  @Override protected void initData() {

  }

  @Override protected void oNext(String resulte, String method) {

  }

  @Override
  protected void oError() {

  }

  private class MyPagerAdapter extends FragmentPagerAdapter {

    public MyPagerAdapter(FragmentManager fm) {
      super(fm);
    }

    @Override public Fragment getItem(int position) {
      return fragments.get(position);
    }

    @Override public int getCount() {
      return mTitles.length;
    }

    @Override public CharSequence getPageTitle(int position) {
      return mTitles[position];
    }
  }
}
